package org.hot100_6.leetcode1;

import java.util.HashMap;

public class Solution {
    public int[] twoSum(int[] nums, int target) {

        int [] res  = new int[2];

        HashMap<Integer,Integer> hashMap = new HashMap<>();

        for (int i = 0; i < nums.length; i++) {
            hashMap.put(nums[i],i);
        }


        for (int i = 0; i < nums.length; i++) {
            int num2 = target - nums[i];

            if (hashMap.containsKey(num2) && hashMap.get(num2)!=i){
                res[0] =i;
                res[1]= hashMap.get(num2);
            }
        }


        return res;
    }
}
